/**
 * 
 */
package com.jkl.controller.project;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jkl.entity.project.dto.VillageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.jkl.entity.project.extend.PJVillage;
import com.jkl.service.project.inter.IPJProjectExtendService;

import lombok.extern.slf4j.Slf4j;

/**
 * @author: HXH
 * @Description: 横向扩展业务
 */
@RestController
@RequestMapping("/jky/projectExtend")
@Slf4j
public class ProjectExtendController {
	@Autowired
	private IPJProjectExtendService projectExtendService;

	@PostMapping("/queryVillageList")
	public PageInfo<VillageDTO> queryVillageList(@RequestBody PJVillage param) {
		return projectExtendService.queryVillageList(param);
	}

	@PostMapping("/addVillage")
	public int addVillage(HttpServletRequest request, HttpServletResponse response) {
		String data = request.getParameter("form");
		PJVillage param = JSON.parseObject(data, PJVillage.class);
		List<MultipartFile> fileList = null;
		CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
				request.getSession().getServletContext());
		if (multipartResolver.isMultipart(request)) {
			MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
			fileList = multiRequest.getFiles("files");
		}
		return projectExtendService.addVillage(param, fileList);
	}
}
